/********************************************
 * 功能说明: 
 * 模块名称: 
 * 系统名称: 
 * 软件版权: Frank
 * 系统版本: 1.0.0
 * 开发人员: wangshaohua
 * 开发时间: 2019/10/24 16:04
 * 审核人员: 
 * 相关文档: 
 * 修改记录: 修改日期 修改人员 修改说明
 *********************************************/
package com.spring.arch.message.setup;

import com.spring.arch.common.setup.IApplicationSetup;
import com.spring.arch.common.setup.SetupOrder;
import com.spring.arch.message.enums.BusinessType;
import com.spring.arch.message.model.SmsTemplateConfig;
import com.spring.arch.message.repository.SmsTemplateConfigRepository;
import com.spring.arch.common.setup.IApplicationSetup;
import com.spring.arch.common.setup.SetupOrder;
import com.spring.arch.message.enums.BusinessType;
import com.spring.arch.message.model.SmsTemplateConfig;
import com.spring.arch.message.repository.SmsTemplateConfigRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 短信模板初始化
 * @author wangshaohua
 * @version 1.0.0.1
 * @since 2019/10/24 16:04
 */
@Slf4j
@Component
@SetupOrder(10)
public class MessageSetup implements IApplicationSetup {

    @Autowired
    private SmsTemplateConfigRepository repository;

    /**
     * 短信模板初始化
     */
    @Override
    public boolean initDBData(String... args) {
        log.info("短信服务-模板数据初始化|enter");
        try {

            if(!repository.findByBusinessType(BusinessType.LOGIN).isPresent()) {

                SmsTemplateConfig smsTemplateConfig = new SmsTemplateConfig();
                smsTemplateConfig.setBusinessType(BusinessType.LOGIN);
                smsTemplateConfig.setTemplateCode("SMS_174805289");

                SmsTemplateConfig smsTemplateConfig1 = new SmsTemplateConfig();
                smsTemplateConfig1.setBusinessType(BusinessType.WORKORDER_FOUCES);
                smsTemplateConfig1.setTemplateCode("SMS_174805237");

                SmsTemplateConfig smsTemplateConfig2 = new SmsTemplateConfig();
                smsTemplateConfig2.setBusinessType(BusinessType.WORKORDER_RECEIVE);
                smsTemplateConfig2.setTemplateCode("SMS_174810268");

                SmsTemplateConfig smsTemplateConfig3 = new SmsTemplateConfig();
                smsTemplateConfig3.setBusinessType(BusinessType.WORKORDER_TIMEOUT);
                smsTemplateConfig3.setTemplateCode("SMS_174805271");

                SmsTemplateConfig smsTemplateConfig4 = new SmsTemplateConfig();
                smsTemplateConfig4.setBusinessType(BusinessType.CHANGE_PASSWORD);
                smsTemplateConfig4.setTemplateCode("SMS_142065503");

                repository.save(smsTemplateConfig);
                repository.save(smsTemplateConfig1);
                repository.save(smsTemplateConfig2);
                repository.save(smsTemplateConfig3);
                repository.save(smsTemplateConfig4);
            }

        } catch(Exception e) {
            return false;
        }

        log.info("短信服务-模板数据初始化|end");
        return true;
    }
}
